package resource

import (
	"fmt"
	"time"

	"github.com/infraboard/mcube/pb/resource"
	"github.com/rs/xid"
)

func (r *Resource) MakeDefault() {
	if r.Meta == nil {
		r.Meta = resource.NewMeta()
	}

	if r.Meta.Id == "" {
		r.Meta.Id = xid.New().String()
	}
	if r.Meta.CreateAt == 0 {
		r.Meta.CreateAt = time.Now().Unix()
	}
}

// 资源概述
func (r *Resource) ShortDesc() string {
	return fmt.Sprintf("%s, cpu: %d, memory: %dM, ip: %v",
		r.Spec.Name,
		r.Spec.Cpu,
		r.Spec.Memory,
		r.Spec.PrivateAddress,
	)
}

func NewResource() *Resource {
	return &Resource{
		Meta: resource.NewMeta(),
		Spec: NewSpec(),
	}
}

func NewSpec() *Spec {
	return &Spec{
		Extra: map[string]string{},
	}
}
